function checkContent() {
	var maxlimit = 140;
	var content = document.getElementById('content_textarea');
	var length = content.value.length;
	var contentMsg = document.getElementById('word-count');
	if (length > maxlimit) {
		content.value = content.value.substring(0, 140);
	} else
		contentMsg.innerHTML = maxlimit - length;
}

function showComment(id) {
	var commentBox = document.getElementById("comment" + id);
	var commentListUl=document.getElementById("commentList"+id);
	var forwardBox = document.getElementById("forward" + id);
	var commentForm = document.getElementById("commentForm" + id);
	var commentFormArea = document.getElementById("commentFormArea" + id);
	//alert(OuterHTML(commentBox));
	
	$.ajax({
		url:"showComment.action",
		type:"get",
		datatype:"json",
		data:{mblogId: id },
		success:function(data)
		{
			//alert("success");
			if (commentBox.style.display == "none") {
				forwardBox.style.display = "none";
				commentBox.style.display = "block";
				var innerHtml="";
				for(var i=0; i< data.commentList.length; i++){
					//alert("TIME TIME TIME TIME TIME" +data.commentList[i].commentTime.split('T'));
					innerHtml +="<li><img src='img/avatar/"+data.userList[i].avatar+ "'/><span class='commenter'>" + data.userList[i].nickname + "</span>:<span>"+ data.commentList[i].commentTxt+"</span><span class='time'>" + data.commentList[i].commentTime.split('T')+"</span><div class='clear'></div></li>";
				}
				innerHtml +="</ul>";
				commentListUl.innerHTML = innerHtml;
				commentFormArea.innerHTML = "<textarea id='comment-textarea"
						+ id
						+ "' name='commentContent'></textarea><input name='flagOriginal' type='checkbox' /><div class='tip'>同时转发到我的微博</div><input onclick='return checkCount(\"comment-textarea"
						+ id
						+ "\");' class='sys-pic comment-but' type='image'	src='img/transparent.png' />";
			} else {
				commentBox.style.display = "none";
			}
			//alert(data.commentList[0].commentTxt);
		},
		error:function(data)
		{
			alert("Show comment Wrong!");
		}
	});
	
	
}

function OuterHTML(element) {
    var container = document.createElement("div");
    container.appendChild(element.cloneNode(true));
    return container.innerHTML;
}

function showForward(id) {
	var commentBox = document.getElementById("comment" + id);
	var forwardBox = document.getElementById("forward" + id);
	var forwardForm = document.getElementById("forwardForm" + id);
	var forwardFormArea = document.getElementById("forwardFormArea" + id);	
	var blogger = document.getElementById("blogger" + id).innerHTML;
	var accumulation = document.getElementById("blog" + id).innerHTML;
	var preText = "//@" + blogger + ": " + accumulation;
	var cite = document.getElementById("cite" + id);
	if (cite == null) {
		preText = "";
	}
	if (forwardBox.style.display == "none") {
		commentBox.style.display = "none";
		forwardBox.style.display = "block";
		forwardFormArea.innerHTML = "<textarea id='forward-textarea"
				+ id
				+ "' name='forwardContent'>"
				+ preText
				+ "</textarea><input onclick='return checkCount(\"forward-textarea"
				+ id
				+ "\");' class='sys-pic comment-but' type='image'	src='img/transparent.png' />";
	} else {
		forwardBox.style.display = "none";
	}
}

function checkCount(id) {
	var maxlimit = 140;
	var content = document.getElementById(id).value;
	var length = content.length;
	if (length > maxlimit) {
		alert("字数超过140字限制，请删减部分文字");
		return false;
	}
}

function checkEmpty(){
	if(document.getElementById('content_textarea').value.length==0){
		alert("您不能发布空微博");
		return false;
	}
	return true;
}